package com.holdtime.jtt809.taxi.module.web.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import com.holdtime.jtt809.taxi.module.entity.PlatformLogoutLogDO;
import com.holdtime.jtt809.taxi.module.model.vo.PlatformLogoutLogPageReqVO;
import com.holdtime.jtt809.taxi.module.model.vo.PlatformLogoutLogRespVO;
import com.holdtime.jtt809.taxi.module.model.vo.PlatformLogoutLogSaveReqVO;
import com.holdtime.jtt809.taxi.module.service.PlatformLogoutLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 下级平台登出日志")
@RestController
@RequestMapping("/taxi/platform-logout-log")
@Validated
public class PlatformLogoutLogController {

    @Resource
    private PlatformLogoutLogService platformLogoutLogService;

    @PostMapping("/create")
    @Operation(summary = "创建下级平台登出日志")
    @PreAuthorize("@ss.hasPermission('taxi:platform-logout-log:create')")
    public CommonResult<String> createPlatformLogoutLog(@Valid @RequestBody PlatformLogoutLogSaveReqVO createReqVO) {
        return success(platformLogoutLogService.createPlatformLogoutLog(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新下级平台登出日志")
    @PreAuthorize("@ss.hasPermission('taxi:platform-logout-log:update')")
    public CommonResult<Boolean> updatePlatformLogoutLog(@Valid @RequestBody PlatformLogoutLogSaveReqVO updateReqVO) {
        platformLogoutLogService.updatePlatformLogoutLog(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除下级平台登出日志")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('taxi:platform-logout-log:delete')")
    public CommonResult<Boolean> deletePlatformLogoutLog(@RequestParam("id") String id) {
        platformLogoutLogService.deletePlatformLogoutLog(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得下级平台登出日志")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('taxi:platform-logout-log:query')")
    public CommonResult<PlatformLogoutLogRespVO> getPlatformLogoutLog(@RequestParam("id") String id) {
        PlatformLogoutLogDO platformLogoutLog = platformLogoutLogService.getPlatformLogoutLog(id);
        return success(BeanUtils.toBean(platformLogoutLog, PlatformLogoutLogRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得下级平台登出日志分页")
    @PreAuthorize("@ss.hasPermission('taxi:platform-logout-log:query')")
    public CommonResult<PageResult<PlatformLogoutLogRespVO>> getPlatformLogoutLogPage(@Valid PlatformLogoutLogPageReqVO pageReqVO) {
        PageResult<PlatformLogoutLogDO> pageResult = platformLogoutLogService.getPlatformLogoutLogPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, PlatformLogoutLogRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出下级平台登出日志 Excel")
    @PreAuthorize("@ss.hasPermission('taxi:platform-logout-log:export')")
    public void exportPlatformLogoutLogExcel(@Valid PlatformLogoutLogPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<PlatformLogoutLogDO> list = platformLogoutLogService.getPlatformLogoutLogPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "下级平台登出日志.xls", "数据", PlatformLogoutLogRespVO.class,
                        BeanUtils.toBean(list, PlatformLogoutLogRespVO.class));
    }

}